﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
#if NET_2_0
using RaisingStudio.Linq;
#endif
using RaisingStudio.Data.Linq;
using RaisingStudio.Data.Providers;
using RaisingStudio.Data;
using RaisingStudio.Data.SharePoint.Entities;

namespace SharePointWindowsFormsApplication
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataContext dc = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
            dc.Log = Console.Out;
            QueryableData<SampleCustomList> scl = new QueryableData<SampleCustomList>(dc);
            var sc = from s in scl
                     select s;
            foreach (var s in sc)
            {
                Console.WriteLine(s.Title);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DataContext dc = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
            dc.Log = Console.Out;
            QueryableData<SampleCustomList> scl = new QueryableData<SampleCustomList>(dc);
            var sc = from s in scl
                     where s.Title == "a"
                     select s;
            foreach (var s in sc)
            {
                Console.WriteLine(s.Title);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DataContext dc = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
            dc.Log = Console.Out;
            var expressionData = dc.GetExpressionData<_SampleCustomList, SampleCustomList>(SampleCustomList._);
            var sc = from s in expressionData
                     where s.Title == "a" | s.Title.StartsWith("b")
                     select s;
            foreach (var s in sc)
            {
                Console.WriteLine(s.Title);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            DataContext dc = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
            dc.Log = Console.Out;
            var expressionData = dc.GetExpressionData<_SampleCustomList, SampleCustomList>(SampleCustomList._);
            var sc = from s in expressionData
                     where s.Title == "a" | s.Title == "b2"
                     select s;
            foreach (var s in sc)
            {
                Console.WriteLine(s.Title);
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            DataContext dc = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
            dc.Log = Console.Out;
            var expressionData = dc.GetExpressionData<_SampleCustomList, SampleCustomList>(SampleCustomList._);
            var sc = from s in expressionData
                     where s.Title == "a" | s.Title == "b2"
                     orderby s.Title descending
                     select s;
            foreach (var s in sc)
            {
                Console.WriteLine(s.Title);
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            DataContext dc = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
            dc.Log = Console.Out;
            var expressionData = dc.GetExpressionData<_SampleCustomList, SampleCustomList>(SampleCustomList._);
            var sc = from s in expressionData
                     where s.Title == "a" | s.Title.Like("b")
                     orderby s.Title descending
                     select s;
            foreach (var s in sc)
            {
                Console.WriteLine(s.Title);
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            DataContext dc = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
            dc.Log = Console.Out;
            QueryableData<SampleCustomList> scl = dc.GetQueryableData<SampleCustomList>();
            var sc = from s in scl
                     where s.Title == "a" || s.Title.StartsWith("b")
                     orderby s.Title descending
                     select s;
            foreach (var s in sc)
            {
                Console.WriteLine(s.Title);
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            DataContext dc = new DataContext(DatabaseType.SHAREPOINT, "http://moss/Docs");
            dc.Log = Console.Out;
            QueryableData<SampleCustomList> scl = dc.GetQueryableData<SampleCustomList>();
            var sc = from s in scl
                     where (s.Title == "a" || s.Title.StartsWith("b")) && (s.SingleLineOfText != null) 
                     orderby s.Title, s.SingleLineOfText descending
                     select s;
            foreach (var s in sc)
            {
                Console.WriteLine(s.Title);
            }
        }
    }
}
